/* ====================================================================
 * (#)Header: DataProvider.java
 * (#)Revision: 
 * (#)Date Created: 2011-04-01
 * (#)Created By: Karol Wozniak
 * ====================================================================
 *
 * Copyright (c) 2007 karolak .  All rights reserved.
 *
 * ====================================================================
 * 
 * The software application represented here is the sole property of 
 * karolak. Its unauthorized utilization is expressly prohibited.
 * 
 * ====================================================================
 */

package com.karolak.data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.karolak.data.file.FileDataProvider;



public class DataProvider {

	private double[] data;
	private int currentIx;
	public DataProvider() {
		loadData();
	}

	public double getLast() {
		double last = data[currentIx];
		if (currentIx < data.length - 1) {
			currentIx++;
		}
		return last;
	}
	
	public int getDataSize() {
		return getData().length;
	}
	
	public boolean isMoreData() {
		if (currentIx < data.length - 1) {
			return true;
		} else {
			return false;
		}
	}
	
	
	protected void loadData() {
		//data = getY(getX(128, 8 * 128));
		data = getFileData();
	}
	
	public static double[] getX(int period, int size) {
		double[] x = new double[size];
		for (int i = 0; i < size; i++) {
			double d = i * 2. * Math.PI / period;
			x[i] = d;
		}
		return x;
	}

	public static double[] getX() {
		int size = 1024;
		int period = 1024;
//		int period = 100 +  Double.valueOf(Math.random() * 200).intValue();
		return getX(period, size);
	}
	
	public static double[] getY(double[] x) {
		double y0 = 1;
		double[] y = new double[x.length];
		for (int i = 0; i < x.length; i++) {
			//y[i] = Math.sin(x[i]) + 0.5 * Math.sin(x[i] * 3);
			double xv = x[i];// * (10 + Math.random() * 10);
			y[i] = y[i] + y0;
			y[i] = y[i] + 0.5 * Math.sin(xv);
//			y[i] = y[i] + .5 * Math.cos(xv * 3 * Math.random());
//			y[i] = y[i] + 0.5 * Math.cos(xv * 9);
			y[i] = y[i] + 0.25 * Math.cos(xv * 2);
//			y[i] = y[i] + 0.3 * Math.random();

			//y[i] = Math.sin(x[i]);
		}
		return y;
	}	
	
	public static double[] getX(int size) {
		double[] x = new double[size];
		for (int i = 0; i < size; i++) {
			double d = i;
			x[i] = d;
		}
		return x;
	}
	
	public static double[] getFileData() {
		int sampling = 1;
		//double[] data = FileDataProvider.createSignal("target/classes/data-13k.txt", sampling)[1];
		//double[] data = FileDataProvider.createSignal("target/classes/data-13k-mid.txt", sampling)[1];
		double[] data = FileDataProvider.createSignal("target/classes/data-13k-end.txt", sampling)[1];
		//double[] data = FileDataProvider.createSignal("target/classes/data-31k.txt", sampling)[1]; 
		
		return Arrays.copyOf(data, data.length);
	}

	public double[] getData() {
		return data;
	}
}
